home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 140
/
(Vol 140) Sep 19 2011.iso
/
Games
/
football_extravaganza.swf
/
scripts
/
DefineSprite_140
/
frame_1
/
DoAction.as
Wrap
Text File
|
2011-09-19
|
10KB
|
396 lines
function newMatch()
{
start_whist = false;
end_whist = false;
time = getTimer();
start_time = 0;
match_end = false;
left_score = 0;
right_score = 0;
extratime = false;
running = false;
}
function centre()
{
ball._x = clip_width / 2;
ball._y = clip_height / 2;
left._x = 40;
left._y = clip_height / 2;
right._x = clip_width - 40;
right._y = clip_height / 2;
}
function start_game()
{
ball_xmov = (Math.random() * ball_speed_diff + ball_speed_max) * (ball_side != "R" ? 1 : -1);
ball_ymov = (Math.random() * ball_speed_diff + ball_speed_max) * (0.5 >= Math.random() ? 1 : -1);
_parent.onKick();
if(extratime)
{
over_whist = false;
}
if(start_time == 0)
{
start_time = getTimer();
}
running = true;
}
function start_extratime()
{
match_duration += extratime_duration;
extratime = true;
}
function stop_game()
{
running = false;
time = getTimer();
}
function move_ball()
{
if(!match_end && start_time != 0)
{
s = Math.round((getTimer() - start_time) / 1000,0);
m = Math.floor(s / 60,0);
if(m == 0)
{
time_disp = "00:" + leftPadding(s,2,"0");
}
else
{
time_disp = leftPadding(m,2,"0") + ":" + leftPadding(s - m * 60,2,"0");
}
}
if(!running & !match_end)
{
if(2000 < getTimer() - time && getTimer() - time < 2500)
{
centre();
start_whist = false;
}
if(2500 < getTimer() - time && !start_whist)
{
_parent.onKickOff();
start_whist = true;
}
if(3000 < getTimer() - time)
{
start_game();
}
}
else
{
if(match_duration < getTimer() - start_time)
{
match_end = true;
stop_game();
if(!over_whist)
{
_parent.onGameOver(left_score == 0 && 0 < right_score && !extratime);
over_whist = true;
if(left_score == 0 && 0 < right_score && !extratime)
{
match_end = false;
_parent.onExtraTime();
start_extratime();
}
}
return undefined;
}
ball._x += ball_xmov;
ball._y += ball_ymov;
ballx = ball._x;
bally = ball._y;
if(clip_width - ball._width / 2 < ballx)
{
ball._x = clip_width - ball._width / 2;
ball_xmov *= -1;
if(isGoal())
{
left_score++;
stop_game();
_parent.onRightGoal();
ball._x += ball_xmov * -2;
ball._y += ball_ymov * 2;
return undefined;
}
_parent.onHitWall(1);
}
if(ballx < ball._width / 2)
{
ball._x = ball._width / 2;
ball_xmov *= -1;
if(isGoal())
{
right_score++;
stop_game();
ball._x += ball_xmov * -2;
ball._y += ball_ymov * 2;
_parent.onLeftGoal();
return undefined;
}
_parent.onHitWall(-1);
}
if(clip_height - ball._height / 2 < bally)
{
ball._y = clip_height - ball._height / 2;
ball_ymov *= -1;
_parent.onHitWall(0);
}
if(bally < ball._height / 2)
{
ball._y = ball._height / 2;
ball_ymov *= -1;
_parent.onHitWall(0);
}
if(ball.hitTest(left) && ball_xmov < 0)
{
ball_xmov *= -1;
ball._x = left._x + left._width / 2 + ball._width / 2;
_parent.onKick(-1);
return undefined;
}
if(ball.hitTest(right) && 0 < ball_xmov)
{
ball_xmov *= -1;
ball._x = right._x - (right._width / 2 + ball._width / 2 - Math.abs(ball_xmov));
left._x = 10 + Math.ceil(Math.random() * right._x / 3);
left_mov = Math.sqrt(left_mov * left_mov) * (left._y >= left_targety ? -1 : 1);
_parent.onKick(1);
return undefined;
}
ball.football._rotation += 20 * sign(ball_ymov);
leftMove();
}
}
function leftHit(x, y)
{
if(ball_xmov < 0)
{
if(left._y - left._height / 2 < y && y < left._y + left._height / 2 && x < left._x + left._width && left._x - left._width - ball._width / 2 < x)
{
return true;
}
}
return false;
}
function rightHit(x, y)
{
if(0 < ball_xmov)
{
if(right._y - right._height / 2 < y && y < right._y + right._height / 2 && right._x - right._width / 2 < x && x < right._x + right._width / 2)
{
return true;
}
}
return false;
}
function isGoal()
{
txt = 100;
var x = ball._x - ball._width / 2;
var y = ball._y;
var goal_top = clip_height / 2 - goal_width / 2;
var goal_bottom = clip_height / 2 + goal_width / 2;
if(y >= goal_top && goal_bottom >= y)
{
return true;
}
return false;
}
function rightMove(xdirection, ydirection)
{
var right_top;
var right_left;
var right_bottom;
var right_right;
var movie_top = 0;
var movie_bottom = clip_height;
var movie_left = 0;
var movie_right = clip_width;
if(running)
{
right._y += right_speed * ydirection;
right._x += right_speed * xdirection;
right_top = right._y - right._height / 2;
right_bottom = right._y + right._height / 2;
right_left = right._x - right._width / 2;
right_right = right._x + right._width / 2;
if(right_top < movie_top)
{
right._y = right._height / 2;
}
if(movie_bottom < right_bottom)
{
right._y = movie_bottom - right._height / 2;
}
if(movie_right < right_right)
{
right._x = movie_right - right._width / 2;
}
if(right_left < movie_left)
{
right._x = right._width / 2;
}
}
}
function rightMove_mouse(x, y)
{
var right_top;
var right_left;
var right_bottom;
var right_right;
var movie_top = 0;
var movie_bottom = clip_height;
var movie_left = 0;
var movie_right = clip_width;
right._y = y;
right_top = right._y - right._height / 2;
right_bottom = right._y + right._height / 2;
right_left = right._x - right._width / 2;
right_right = right._x + right._width / 2;
if(right_top < movie_top)
{
right._y = right._height / 2;
}
if(movie_bottom < right_bottom)
{
right._y = movie_bottom - right._height / 2;
}
if(movie_right < right_right)
{
right._x = movie_right - right._width / 2;
}
if(right_left < movie_left)
{
right._x = right._width / 2;
}
}
function leftMove()
{
if(running)
{
if(ball_xmov < 0)
{
if(ball_side == "R")
{
left_targety = getLeftHitPoint(ball._x,ball._y,ball_xmov,ball_ymov);
left_mov = Math.sqrt(left_mov * left_mov) * (left._y >= left_targety ? -1 : 1);
}
ball_side = "L";
if(!leftHit(left._x,left_targety))
{
left._y += left_mov;
}
}
else
{
ball_side = "R";
ball_xmove += 0.3 * (0.5 >= Math.random() ? -1 : 1);
ball_ymov += 0.3 * (0.5 >= Math.random() ? -1 : 1);
if(ball_xmov * sign(ball_xmov) < ball_ymov * sign(ball_ymov))
{
ball_ymov *= 0.75;
}
}
}
}
function getLeftHitPoint(x, y, xmov, ymov)
{
hitx = 0;
hity = 0;
left_guess_count = 0;
while(left._x < x)
{
left_guess_count++;
if(left_guess_power < left_guess_count)
{
break;
}
x += xmov;
y += ymov;
hitx = x;
hity = y;
if(clip_width - ball._width / 2 < hitx)
{
x = clip_width - ball._width / 2;
xmov *= -1;
}
if(hitx < ball._width / 2)
{
x = ball._width / 2;
xmov *= -1;
}
if(clip_height - ball._height / 2 < hity)
{
y = clip_height - ball._height / 2;
ymov *= -1;
}
if(hity < ball._height / 2)
{
y = ball._height / 2;
ymov *= -1;
}
}
return y;
}
function sign(n)
{
if(n < 0)
{
return -1;
}
if(0 < n)
{
return 1;
}
if(n == 0)
{
return 0;
}
}
function leftPadding(str, n, paddingChr)
{
var i;
str += "";
padding = "";
i = 0;
while(i < n - str.length)
{
padding += paddingChr;
i++;
}
return padding + str;
}
var clip_height = this._height;
var clip_width = this._width;
var goal_width = 178.6 - 2 * ball._height;
var ball_speed_diff = 2;
var ball_speed_max = 5;
var ball_xmov;
var ball_ymov;
var right_speed = 40;
var ball_side = "R";
var left_targety = 0;
var left_speed = 3;
var left_mov = 2;
var left_guess_power = 200;
var left_guess_count = 0;
var left_score = 0;
var right_score = 0;
var start_whist = false;
var over_whist = false;
var time = getTimer();
var start_time = 0;
var match_duration = 150000;
var extratime_duration = 60000;
var match_end = false;
var running = false;
var extratime = false;
var crowd_sound_hush;
if(!crowd_sound_hush)
{
crowd_sound_hush = new Sound(this);
crowd_sound_hush.attachSound("crowd_sound_hush");
crowd_sound_hush.start(0,10000);
}
time_disp = "00:00";